package fuse.LaCollaFS;

import java.util.ArrayList;
import java.util.Hashtable;

public class Operacions {
	private Hashtable<String, ArrayList<ArrayList<Comparable>>> operacions;

	private Hashtable<Integer, ArrayList<Comparable>> identificadors;

	public Operacions() {
		operacions = new Hashtable<String, ArrayList<ArrayList<Comparable>>>();
		identificadors = new Hashtable<Integer, ArrayList<Comparable>>();

	}

	public void AfegirOperacio(int id, String path, String member,
			String operacio) {

		ArrayList members = new ArrayList();
		String groupId = "hola";

		ArrayList<Comparable> v = new ArrayList<Comparable>();
		v.add(0, path);
		v.add(1, operacio);
		v.add(2, id);
		v.add(3, member);

		ArrayList<ArrayList<Comparable>> p = operacions.get(path);
		if (p == null)
			p = new ArrayList<ArrayList<Comparable>>();
		p.add(v);

		operacions.put(path, p);
		identificadors.put(id, v);

	}

	public ArrayList<ArrayList<Comparable>> BuscarperPath(String path) {
		//System.out.println("Operacions: He arribat fins aqui!!!");
		return operacions.get(path);
	}

	public int TreureOperacio(int id) {
		int i;
		i = 0;
		try {
			ArrayList v = identificadors.get(id);
			identificadors.remove(id);
			operacions.remove(v.get(0));
		} catch (Exception e) {
			i = -1;
		}
		return i;
	}

	/*
	 * public int TreureOperacio(String path) {
	 * 
	 * int i = 0; try{ ArrayList<ArrayList<Comparable>> v =
	 * operacions.get(path); identificadors.remove(v.get(2));
	 * operacions.remove(v.get(0)); } catch (Exception e) { i = -1; } return i; }
	 */

}
